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

Y Even

The document outlines an open-ended program by Ishika Pachori focused on developing a C++ program to find the shortest path in a road network represented as a graph. It discusses the theory behind graph representation, the shortest path problem, and the implementation of Dijkstra's Algorithm. The learning outcomes include understanding graph representation, implementing algorithms, and evaluating program performance across various datasets.

Uploaded by

Kashish Gulati
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)
6 views8 pages

Y Even

The document outlines an open-ended program by Ishika Pachori focused on developing a C++ program to find the shortest path in a road network represented as a graph. It discusses the theory behind graph representation, the shortest path problem, and the implementation of Dijkstra's Algorithm. The learning outcomes include understanding graph representation, implementing algorithms, and evaluating program performance across various datasets.

Uploaded by

Kashish Gulati
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/ 8

Open-Ended Program

Name: Ishika Pachori


Enrollment No.:A2305222358
Subject: ADA (CSE303)
Section: 5CSE - Y

Category Code Name of Experiment Max. Marks Sign.


of Assignment Marks obtaine of Faculty
d

Design Based PR A road network can be 10


Open Ended (10) considered as a graph
experiment with positive weights.
The nodes represent
road junctions and each
edge of the graph is
associated with a road
segment between two
junctions. The weight of
an edge may
correspond to the
length of the associated
road segment, the time
needed to traverse the
segment or the cost of
traversing the segment.
Using directed edges it
is also possible to
model one-way streets.
Such graphs are special
in the sense that some
edges are more
important than others
for long distance travel
(e.g. highways). This
property has been
formalized using the
notion of highway
dimension. There are a
great number of
algorithms that exploit
this property and are
therefore able to
compute the shortest
path a lot quicker than
would be possible on
general graphs.
Develop a program to
find the shortest path
from each node to solve
the road network
problem.

OPEN ENDED EXPERIMENT

Date: 24 October 2024

Objective: A road network can be considered as a graph with positive


weights. The nodes represent road junctions, and each edge of the graph
is associated with a road segment between two junctions. The weight of
an edge may correspond to the length of the associated road segment,
the time needed to traverse the segment or the cost of traversing the
segment. Using directed edges, it is also possible to model one-way
streets. Such graphs are special in the sense that some edges are more
important than others for long distance travel (e.g. highways). This
property has been formalized using the notion of highway dimension.
There are a great number of algorithms that exploit this property and are
therefore able to compute the shortest path a lot quicker than would be
possible on general graphs. Develop a program to find the shortest path
from each node to solve the road network problem.

Software Used: C++

Theory:
A road network can be represented as a graph, where nodes (vertices) correspond to road
junctions, and edges represent the road segments connecting these junctions. Each edge
carries a positive weight, which may represent factors such as distance, time, or cost of
travel. The challenge of determining the most efficient route across this network—whether to
minimize time, distance, or cost—is known as the shortest path problem. This problem is
critical in applications like navigation systems, where finding the optimal route between
locations is essential, or in logistics, where cost efficiency in delivery planning is a priority.
Solving the shortest path problem effectively becomes even more important in large
networks with millions of nodes and edges.
In a weighted graph, each edge has a numerical value or weight. For road networks, nodes
symbolize intersections, edges represent the connecting roads, and weights can indicate
travel time, distance, or cost. For example, if weights represent time, the goal is to minimize
travel time. If they represent distance, the objective is to minimize the total distance covered.
Road networks can be modeled using two types of graphs: undirected graphs, which
represent roads that allow two-way travel, and directed graphs, used for one-way streets
where travel is restricted to a specific direction.
The shortest path problem involves finding a route between two nodes that minimizes the
sum of the edge weights along that path. Two main variations of this problem exist: the
single-source shortest path, where the goal is to find the shortest path from a given node to
all other nodes, and the all-pairs shortest path, where the objective is to find the shortest path
between every pair of nodes. Given the vast size and complexity of road networks, solving
this problem efficiently is critical to ensure computation remains manageable.
Dijkstra's Algorithm is the most widely used solution for graphs with non-negative weights.
Created by Edsger Dijkstra in 1956, the algorithm follows a greedy approach. It works by
selecting the node with the smallest known distance from the source and exploring its
neighbors to find shorter paths. This process continues until all reachable nodes have been
processed.
The algorithm begins by setting the distance from the source node to itself as 0 and to all
other nodes as infinity. A priority queue (min-heap) is used to keep track of nodes based on
their distance from the source. As the algorithm explores each node’s neighbors, it updates
the shortest known distance if a shorter path is found and adds that neighbor to the queue if
its distance was modified. The process terminates when all nodes are visited or when the
queue contains no more nodes with finite distances.
Dijkstra's Algorithm is efficient, with a time complexity of O((V + E) log V), where V
represents the number of nodes and E the number of edges. It performs particularly well on
sparse graphs, where the number of edges is significantly smaller than the number of
possible node connections. While optimal for graphs with positive edge weights, Dijkstra's
Algorithm is not suited for graphs with negative weights.
In real-world road networks, certain roads, such as highways, are more crucial for long-
distance travel. Algorithms can be further optimized by prioritizing these major routes, a
concept known as highway dimension. By focusing on key roads, pathfinding efficiency
improves, especially in large-scale networks.
In conclusion, the shortest path problem is a central issue in transportation and logistics, and
Dijkstra’s Algorithm provides a practical and efficient solution for finding the shortest
paths in graphs with positive edge weights, making it ideal for road networks.

Code:
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;

typedef pair<int, int> pii; // Pair to represent a node and its distance (distance, node)

// Function to perform Dijkstra's Algorithm from a given source node


vector<int> dijkstra(int src, int n, vector<vector<pii>>& adj) {
// Distance vector to store the shortest distance from the source to every node
vector<int> dist(n, INT_MAX);
dist[src] = 0; // Distance from source to itself is 0

// Min-heap priority queue to select the edge with the minimum weight
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, src}); // Push the source node into the queue (distance, node)

while (!pq.empty()) {
int u = pq.top().second; // Get the node with the smallest distance
int d = pq.top().first; // Get the corresponding distance
pq.pop(); // Remove the node from the queue

// Explore all neighbors of node u


for (auto edge : adj[u]) {
int v = edge.first; // Neighboring node
int weight = edge.second; // Edge weight (distance between u and v)

// If a shorter path is found to node v through u


if (dist[v] > d + weight) {
dist[v] = d + weight; // Update the shortest distance to v
pq.push({dist[v], v}); // Push the updated distance to the queue
}
}
}
return dist; // Return the distance vector
}

int main() {
int n, m; // n: number of nodes (junctions), m: number of edges (road segments)
cout << "Enter number of junctions (nodes) and road segments (edges): ";
cin >> n >> m;

// Adjacency list to represent the graph: (neighbor, weight)


vector<vector<pii>> adj(n);

cout << "Enter the road segments (node1 node2 weight) one by one:\n";
for (int i = 0; i < m; ++i) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w}); // Directed edge from u to v with weight w
adj[v].push_back({u, w}); // For undirected graphs, add the reverse edge
}

cout << "\nShortest paths from each junction:\n";

// Find shortest path from each node (junction) to all other nodes
for (int src = 0; src < n; ++src) {
vector<int> distances = dijkstra(src, n, adj);
cout << "From junction " << src << ":\n";
for (int i = 0; i < n; ++i) {
cout << "To junction " << i << ": " << distances[i] << endl;
}
cout << "--------------------------\n";
}

return 0;
}

Output :
Learning Outcome:

• Understanding how graphs are represented and the key shortest path algorithms like
Dijkstra's and Bellman-Ford.

• Implementing Dijkstra's algorithm to calculate the shortest paths in a graph.

• Investigating the concept of highway dimension and its advantages for optimizing
pathfinding.

• Testing different highway dimension metrics and optimization strategies.

• Evaluating the program's performance across various road network datasets.


Internal Assessment (Design Based Experiment) sheet for Lab Experiment
Department of Computer Science & Engineering
Amity University, Noida (UP)

Analysis and
Design of
Programme B. Tech CSE Course Name
Algorithm

Course Code CSE303 Semester 5

Student Name Ishika Pachori Enrollment No. A2305222358

Marking Criteria

Criteria Total Marks Marks Obtained Comments

Designing Concept (D) 3

Application of Knowledge (E) 2

Performance (F) 3

Result (G) 2

Total 10

You might also like