Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions Team_79-Public_Welfare_Transportation_Management/CODE
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>

#define MAX_VERTICES 100

// Structure to represent an edge in the graph
struct Edge {
int destination;
int weight;
struct Edge* next;
};

// Structure to represent a vertex in the graph
struct Vertex {
struct Edge* head;
};

// Function to create a new edge
struct Edge* createEdge(int destination, int weight) {
struct Edge* newEdge = (struct Edge*)malloc(sizeof(struct Edge));
newEdge->destination = destination;
newEdge->weight = weight;
newEdge->next = NULL;
return newEdge;
}

// Function to add an edge to the graph
void addEdge(struct Vertex* graph, int source, int destination, int weight) {
struct Edge* newEdge = createEdge(destination, weight);
newEdge->next = graph[source].head;
graph[source].head = newEdge;
}

// Function to find the shortest route using Dijkstra's algorithm
void dijkstra(struct Vertex* graph, int vertices, int start, int end) {
int* distance = (int*)malloc(vertices * sizeof(int));
bool* visited = (bool*)malloc(vertices * sizeof(bool));

// Initialize distance array and visited array
for (int i = 0; i < vertices; ++i) {
distance[i] = INT_MAX;
visited[i] = false;
}
distance[start] = 0;

// Dijkstra's algorithm
for (int count = 0; count < vertices - 1; ++count) {
int minDistance = INT_MAX, minIndex = -1;
for (int v = 0; v < vertices; ++v) {
if (!visited[v] && distance[v] < minDistance) {
minDistance = distance[v];
minIndex = v;
}
}

visited[minIndex] = true;

// Update distance value of the adjacent vertices of the picked vertex.
struct Edge* edge = graph[minIndex].head;
while (edge != NULL) {
int dest = edge->destination;
if (!visited[dest] && distance[minIndex] != INT_MAX && distance[minIndex] + edge->weight < distance[dest]) {
distance[dest] = distance[minIndex] + edge->weight;
}
edge = edge->next;
}
}

// Print the shortest distance
printf("Shortest distance between city %d and city %d is %d\n", start, end, distance[end]);

// Free allocated memory
free(distance);
free(visited);
}

int main() {
int vertices, edges;
printf("Enter the number of cities: ");
scanf("%d", &vertices);

struct Vertex* graph = (struct Vertex*)malloc(vertices * sizeof(struct Vertex));
for (int i = 0; i < vertices; ++i) {
graph[i].head = NULL;
}

printf("Enter the number of connections between cities: ");
scanf("%d", &edges);

printf("Enter connections and distances (source destination weight):\n");
for (int i = 0; i < edges; ++i) {
int source, destination, weight;
scanf("%d %d %d", &source, &destination, &weight);
addEdge(graph, source, destination, weight);
}

int start, end;
printf("Enter the city numbers for which you want to find the shortest distance: ");
scanf("%d %d", &start, &end);

dijkstra(graph, vertices, start, end);

// Free allocated memory
for (int i = 0; i < vertices; ++i) {
struct Edge* edge = graph[i].head;
while (edge != NULL) {
struct Edge* temp = edge;
edge = edge->next;
free(temp);
}
}
free(graph);

return 0;
}
12 changes: 12 additions & 0 deletions Team_79-Public_Welfare_Transportation_Management/OUTPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Enter the number of cities: 4
Enter the number of connections between cities: 5
Enter connections and distances (source destination weight):
0 1 10
0 2 15
1 2 5
1 3 20
2 3 6
Enter the city numbers for which you want to find the shortest distance: 0 3
Shortest distance between city 0 and city 3 is 21


10 changes: 10 additions & 0 deletions Team_79-Public_Welfare_Transportation_Management/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Domain : Public Welfare
Public Welfare Transportation Management

Link For Video [Explanation Of The Project] :

https://drive.google.com/drive/folders/1072Nc5LqnpnUebOOlsj6QGmvbMwjBSWP?usp=sharing

Develop a system to optimize transportation routes and schedules in a city. (Finding Shortest Routes and Representing the transportation Network).

The system for optimizing transportation routes in a city focuses on finding the shortest routes and representing the transportation network efficiently. By gathering data on the city's transportation infrastructure and representing it as a graph, the system uses algorithms like Dijkstra's to calculate the shortest path between two locations, considering factors such as distance, travel time.This system aims to improve transportation efficiency and reduce travel times for commuters, ultimately enhancing the overall transportation experience in the city.