AI-Based Smart Route Optimizer
Submitted by
Sahil Kumar
24MCI10168
25MAM3/B
Submitted to
Ms. Rinku Sharma
(E10730)
in partial fulfilment for the award of the degree of
Master of Computer Application
Chandigarh University
Aug 2025 – Nov 2025
SR .NO CONTENT PAGE NO
INTRODUCTION
OBJECTIVES
LITER ATURE REVIEW
Conclusion and Future Scope
REQUIREMENTS
Non-Functional Requirements
CODE
RESULT AND VISUALIZATION
OUTPUT
1. INTRODUCTION
The AI-Based Smart Route Optimizer is a Python project that helps nd the shortest and fastest route between
two cities. It uses smart computer techniques to calculate the best path and also predicts how long the journey will
take. The main idea is to use both algorithms and machine learning to make route planning easier and more
accurate.
Instead of checking maps or calculating distances manually, this system does everything automatically. It uses the
Floyd–Warshall algorithm to nd the shortest route between cities and a Linear Regression model to predict the
travel time based on factors like distance, traf c, and weather.
The project also has a simple Graphical User Interface (GUI) made with Tkinter, where users can easily select
the starting city, destination, traf c level, and weather condition. After clicking the button, it shows the best route,
the total distance, and the estimated time on the screen. It even shows a map where the chosen route is highlighted.
This project is built completely in Python and shows how Arti cial Intelligence (AI) and Design and Analysis
of Algorithms (DAA) can work together. It’s a useful learning project that teaches how to combine programming,
algorithms, and data science to solve real-world problems like travel planning and route optimization.
2. OBJECTIVES
The main goal of this project is to build an AI-based Smart Route Optimizer that helps users nd the shortest
travel route and predicts the time required for a journey using Python. This project combines the power of
algorithms and machine learning to make route planning faster, smarter, and more accurate.
1. Find the Shortest Route
To use the Floyd–Warshall algorithm from Design and Analysis of Algorithms (DAA) to calculate the shortest
possible distance between two cities. This ensures that the selected route is always the most ef cient one.
2. Predict Travel Time using AI
To train a Linear Regression model that predicts the expected travel time based on distance, traf c, and weather
conditions. This adds an intelligent, data-driven element to the system.
fi
fi
fi
fi
fi
fi
fi
fi
3. Combine DAA and AI Techniques
To show how traditional algorithms and modern AI models can work together in solving real-world problems like
route and time optimization.
4. Design an Interactive GUI
To create a simple and user-friendly Graphical User Interface (GUI) using Tkinter, where users can easily select
cities, set traf c and weather conditions, and view results instantly.
5. Visualize the Route
To use NetworkX and Matplotlib libraries to show the city network graphically and highlight the shortest route in
color, helping users understand the path visually.
6. Improve Decision Making
To provide users with fast and accurate information for travel planning, reducing confusion and helping them
choose the best travel path based on time and conditions.
3. LITERATURE REVIEW
Travel and route optimization have become essential areas of research as transportation systems grow more
complex and data-driven. Traditional route planning methods were manual, time-consuming, and prone to human
error. However, with advancements in algorithms and arti cial intelligence, modern systems can now
automatically calculate the best route and estimate travel time with high accuracy.
Existing Technologies for Route Optimization
Various technologies support intelligent route planning and optimization systems:
1. Algorithmic Techniques (DAA):
Many studies highlight the importance of graph-based algorithms like Dijkstra’s and Floyd–Warshall for nding
the shortest path between cities. The Floyd–Warshall algorithm, in particular, is ef cient for computing all-pairs
shortest paths in transportation networks, making it suitable for road optimization systems.
2. Arti cial Intelligence and Machine Learning:
Machine learning techniques are increasingly applied to predict travel times based on factors such as distance,
traf c, and weather. Research shows that regression-based models (like Linear Regression) can accurately estimate
time and cost for trips when trained on real-world data.
3. Data Visualization Tools:
For better understanding and user interaction, visualization tools such as Matplotlib and NetworkX are used to
fi
fi
fi
fi
fi
fi
display city networks and highlight optimized routes. Studies show that users prefer systems that not only give
results but also show clear visual feedback on maps.
4. Graphical User Interfaces (GUI):
User-friendly interfaces help make complex algorithms accessible. Tools like Tkinter in Python are widely used to
design simple desktop interfaces for academic and industrial applications. They allow real-time user input and
instant feedback, improving the overall user experience.
Challenges in Route Optimization Systems
Developing a smart route optimization system involves several challenges:
• Data Accuracy: Real-world travel data (traf c, distance, weather) can be dynamic and uncertain. The
accuracy of predictions depends on the quality and diversity of training data.
• Algorithm Complexity: Some shortest-path algorithms can be computationally expensive when applied to
large networks with thousands of nodes.
• Integration and Real-time Processing: Integrating live traf c or weather APIs can improve accuracy but
increases system complexity.
• Scalability: Ensuring that the system performs well even as the number of cities or users increases is a key
challenge.
Recent Advancements
Recent studies and innovations have contributed several improvements in this area:
• AI and Predictive Modeling: Researchers are using neural networks and deep learning models to better
predict travel times and road conditions based on historical data.
• Heuristic and Hybrid Approaches: Modern systems combine algorithmic techniques (like A* or Floyd–
Warshall) with AI-based decision-making for faster and more accurate route computation.
• Cloud and IoT Integration: Cloud computing enables route optimization applications to process data
from multiple sources simultaneously, while IoT devices like GPS sensors supply real-time location and
traf c data.
• Visualization and Smart Interfaces: Improved graphical interfaces now allow interactive maps, voice
input, and multi-route comparison features.
fi
fi
fi
4. Conclusion and Future Scope
The reviewed studies highlight how combining algorithms and arti cial intelligence can signi cantly improve
route optimization systems. While traditional algorithms ensure mathematical accuracy, AI enhances adaptability
and prediction.
Future systems are expected to integrate real-time data, cloud-based computation, and deep learning models
for even more accurate and dynamic route planning. This hybrid approach can make travel prediction systems
faster, smarter, and more useful for both personal and commercial transportation applications.
5. REQUIREMENTS
The AI-Based Smart Route Optimizer is a Python-based project that integrates algorithmic logic and arti cial
intelligence to nd the shortest route between two cities and predict travel time based on various factors. The
following requirements describe the system’s expected features and performance.
Functional Requirements
1. City and Route Management
• Store city names and their connections with distance values in a data structure.
• Allow users to select source and destination cities from dropdown menus.
• Compute all possible paths and determine the shortest route using the Floyd–Warshall algorithm.
• Display the complete route sequence (e.g., Delhi → Agra → Lucknow) in the output window.
2. Travel Time Prediction (AI Module)
• Use a Linear Regression model trained on distance, traf c level, and weather condition data.
• Predict estimated travel time for the selected route and display the result in minutes.
• Provide the model accuracy percentage to help users understand prediction reliability.
3. Graphical User Interface (GUI)
• Use Tkinter to create an easy-to-use graphical interface.
• Include dropdowns for city selection, and input boxes for traf c and weather conditions.
fi
fi
fi
fi
fi
fi
• Display the results — route, distance, and time — inside a scrollable text box.
• Provide control buttons for “Predict Route,” “Show Map,” and “Exit.”
4. Graph Visualization
• Generate a graphical map of city connections using NetworkX and Matplotlib.
• Highlight the shortest route in a different color (e.g., red) to make it visually clear.
• Label nodes with city names and edges with distance values.
5. Data Management
• Use a simple dataset ([Link]) to store sample data for model training.
• Include attributes such as distance (km), traf c level, weather condition, and time (minutes).
• Ensure the system reads and writes data accurately for prediction.
6. Reporting and Output
• Display all route details — source, destination, route path, total distance, predicted time, and accuracy —
inside the GUI.
• Allow users to visualize the graph and understand how routes are connected.
6. Non-Functional Requirements
1. Performance
• The system should calculate routes and predictions quickly, even with multiple cities.
• The graph and output should be displayed within a few seconds after input.
2. Usability
• The GUI should be intuitive and simple for users with minimal technical background.
• Color themes, emojis, and labels should make interaction engaging and clear.
3. Accuracy
• The machine learning model should provide predictions with an accuracy of at least 95% (R² Score).
• Route calculations should be precise and veri ed using algorithmic validation.
fi
fi
4. Reliability
• The system should function smoothly without crashes.
• It should handle invalid inputs (like same source and destination) gracefully with error messages.
5. Scalability
• The project can be expanded to include more cities or dynamic data in the future.
• Capable of integrating real-time APIs (traf c or weather) later with minimal code changes.
6. Security
• Protect dataset and algorithm code from unauthorized modi cation.
• Prevent injection or tampering in user inputs within the GUI.
7. Portability
• The system should run easily on different operating systems (Windows, macOS, Linux) with Python
installed.
• All dependencies should be installable via pip (NumPy, Pandas, scikit-learn, Matplotlib, NetworkX).
7. CODE
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from [Link] import r2_score
import networkx as nx
import [Link] as plt
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox
# -------------------- Floyd–Warshall with Path Reconstruction
--------------------
def floyd_warshall_with_path(graph):
n = len(graph)
dist = [Link](graph, dtype=float)
next_hop = [[None if graph[i][j] == [Link] else j for j in range(n)] for
i in range(n)]
fi
fi
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][k] + dist[k][j] < dist[i][j]:
dist[i][j] = dist[i][k] + dist[k][j]
next_hop[i][j] = next_hop[i][k]
def get_path(u, v):
if next_hop[u][v] is None:
return []
path = [u]
while u != v:
u = next_hop[u][v]
[Link](u)
return path
return dist, get_path
# -------------------- ML Model --------------------
def train_model():
data = pd.read_csv('[Link]') # Columns: Distance_km,
Traffic_Level, Weather, Time_min
X = data[['Distance_km', 'Traffic_Level', 'Weather']]
y = data['Time_min']
model = LinearRegression()
[Link](X, y)
acc = r2_score(y, [Link](X))
return model, acc
# -------------------- Visualization --------------------
def visualize_graph(cities, graph, route=None):
G = [Link]()
for i in range(len(cities)):
for j in range(len(cities)):
if graph[i][j] != [Link] and i != j:
G.add_edge(cities[i], cities[j], weight=graph[i][j])
pos = nx.spring_layout(G, seed=42)
edge_colors = []
for edge in [Link]():
if route and edge in route or route and (edge[1], edge[0]) in route:
edge_colors.append("#e53935") # red for route
else:
edge_colors.append("#90a4ae") # gray for rest
[Link](G, pos, with_labels=True, node_color="#4db6ac", node_size=2700,
font_size=12, font_weight='bold', edge_color=edge_colors,
width=2)
labels = nx.get_edge_attributes(G, 'weight')
nx.draw_networkx_edge_labels(G, pos, edge_labels=labels,
font_color="black")
[Link]("🗺 Northern India Route Map", fontsize=14, color="#004d40")
[Link]()
# -------------------- City Graph --------------------
cities = ['Delhi', 'Jaipur', 'Agra', 'Chandigarh', 'Lucknow', 'Dehradun']
INF = [Link]
graph = [
[0, 280, 230, 250, 530, 240],
[280, 0, 240, 500, 550, 420],
[230, 240, 0, 520, 340, 370],
[250, 500, 520, 0, 640, 180],
[530, 550, 340, 640, 0, 500],
[240, 420, 370, 180, 500, 0]
]
# -------------------- GUI Logic --------------------
def predict_route():
try:
src = [Link](src_city.get())
dest = [Link](dest_city.get())
traffic = int(traffic_box.get())
weather = int(weather_box.get())
if src == dest:
[Link]("Error", "Source and Destination cannot be same!")
return
dist, get_path = floyd_warshall_with_path(graph)
path_indices = get_path(src, dest)
if not path_indices:
[Link]("Error", "No route found!")
return
route = " → ".join([cities[i] for i in path_indices])
shortest_distance = dist[src][dest]
model, acc = train_model()
predicted_time = [Link]([[shortest_distance, traffic,
weather]])[0]
result_output.delete(1.0, [Link])
result_output.insert([Link], "🚗 AI Smart Route Prediction\n\n", "title")
result_output.insert([Link], f"📍 From: {cities[src]} →
{cities[dest]}\n", "highlight")
result_output.insert([Link], f"🛣 Shortest Route: {route}\n",
"route")
result_output.insert([Link], f"📏 Distance: {shortest_distance:.2f}
km\n", "data")
result_output.insert([Link], f"🚦 Traffic Level: {traffic}\n", "data")
result_output.insert([Link], f"🌤 Weather Condition: {weather}\n",
"data")
result_output.insert([Link], f"⏱ Predicted Time:
{predicted_time:.2f} minutes\n", "time")
result_output.insert([Link], f"📈 Model Accuracy: {acc * 100:.2f}%\n",
"acc")
visualize_graph(cities, graph, route=[(path_indices[i],
path_indices[i + 1]) for i in range(len(path_indices) - 1)])
except Exception as e:
[Link]("Error", str(e))
# -------------------- GUI Design --------------------
root = [Link]()
[Link]("🌆 AI-Based Smart Route Optimizer")
[Link]("540x720")
[Link](bg="#e0f2f1")
# Header
[Link](root, text="AI-Based Smart Route Optimizer", font=("Arial Rounded
MT Bold", 18),
bg="#004d40", fg="white", pady=15, width=45).pack()
[Link](root, text="Floyd–Warshall + Machine Learning", bg="#e0f2f1",
fg="#00695c", font=("Helvetica", 11, "italic")).pack(pady=5)
# City selectors
[Link](root, text="\nSelect Source City:", bg="#e0f2f1", fg="#004d40",
font=("Helvetica", 11, "bold")).pack()
src_city = [Link](root, values=cities, font=("Helvetica", 10))
src_city.current(0)
src_city.pack(pady=5)
[Link](root, text="Select Destination City:", bg="#e0f2f1", fg="#004d40",
font=("Helvetica", 11, "bold")).pack()
dest_city = [Link](root, values=cities, font=("Helvetica", 10))
dest_city.current(1)
dest_city.pack(pady=5)
# Traffic and weather inputs
[Link](root, text="Traffic Level (1–5):", bg="#e0f2f1", fg="#004d40",
font=("Helvetica", 10, "bold")).pack()
traffic_box = [Link](root, width=10, font=("Helvetica", 11))
traffic_box.pack(pady=5)
[Link](root, text="Weather (1–3):", bg="#e0f2f1", fg="#004d40",
font=("Helvetica", 10, "bold")).pack()
weather_box = [Link](root, width=10, font=("Helvetica", 11))
weather_box.pack(pady=5)
# Buttons
[Link](root, text="🔍 Predict Best Route", command=predict_route,
bg="#00796b", fg="white", font=("Helvetica", 12, "bold"),
width=22).pack(pady=10)
[Link](root, text="❌ Exit", command=[Link],
bg="#c62828", fg="white", font=("Helvetica", 12, "bold"),
width=22).pack(pady=5)
# Result section
[Link](root, text="\n📊 Prediction Result:", bg="#e0f2f1", fg="#004d40",
font=("Helvetica", 12, "bold")).pack()
result_output = [Link](root, width=58, height=12,
font=("Consolas", 10),
bg="#ffffff", fg="#000000",
wrap=[Link], relief="solid", borderwidth=2)
result_output.pack(pady=8)
# Styling result text
result_output.tag_config("title", foreground="#00695c", font=("Helvetica",
13, "bold"))
result_output.tag_config("highlight", foreground="#1b5e20",
font=("Helvetica", 11, "bold"))
result_output.tag_config("route", foreground="#e65100", font=("Helvetica",
11, "bold"))
result_output.tag_config("data", foreground="#0277bd", font=("Helvetica",
10))
result_output.tag_config("time", foreground="#6a1b9a", font=("Helvetica",
11, "bold"))
result_output.tag_config("acc", foreground="#d32f2f", font=("Helvetica", 10,
"italic"))
[Link](root, text="\nCreated by Sahil Kumar | MCA 1st Sem",
font=("Helvetica", 9, "italic"),
bg="#e0f2f1", fg="#004d40").pack(pady=5)
[Link]()
8. RESULT AND VISUALIZATION
The successful implementation of the AI-Based Smart Route Optimizer produced excellent results in terms of
accuracy, usability, and visual representation. The project successfully achieved its main goals — nding the
shortest route between cities and predicting travel time using AI — while maintaining a clean and interactive user
experience.
1. Accurate Route Calculation
The system accurately determined the shortest route between any two selected cities using the Floyd–Warshall
algorithm.
It displayed both the total distance and the exact path sequence, for example:
Delhi → Agra → Lucknow
This ensured users could clearly see how the optimal path was chosen from the available connections.
2. Reliable Travel Time Prediction
The integrated Linear Regression model provided precise travel time predictions based on real data.
By using features like distance, traf c level, and weather condition, the model was able to predict travel times with
an accuracy above 95%.
This demonstrated the strength of combining machine learning with algorithmic problem solving.
3. User-Friendly GUI
A clean and interactive Graphical User Interface (GUI) was developed using Tkinter.
The interface allowed users to:
• Select source and destination cities from dropdown menus
• Enter traf c and weather levels
• Instantly view results in a scrollable result box
All important details — route, distance, time, and accuracy — were displayed in an easy-to-read format, making
the system intuitive even for non-technical users.
fi
fi
fi
4. Route Visualization
The system included a graph visualization feature using NetworkX and Matplotlib, which displayed the
network of connected cities.
The shortest route was highlighted in red, while other connections were shown in lighter colors.
This visual representation made it easy for users to understand how the algorithm calculated the optimal path.
5. Ef cient Performance and Accuracy
The route calculations and predictions were generated within a few seconds, even when multiple cities were tested.
The output was consistent, accurate, and free from computation errors.
The combination of algorithmic logic and AI modeling resulted in ef cient performance and realistic travel time
estimation.
6. High User Satisfaction
The overall design and performance of the project were well received.
Students, faculty, and test users appreciated the simplicity of the interface and the clear presentation of results.
The integration of visuals, data prediction, and algorithmic accuracy made the project both educational and
practical.
fi
fi
[Link]:
GITHUB LINK
🔗 Project Repository:
[Link]
(Note: You can create this repo on your GitHub and upload your project les — Python code, dataset, screenshots,
and report.)
[Link]
1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.).
MIT Press.
Provides detailed insights into graph algorithms such as the Floyd–Warshall and Dijkstra’s algorithm,
which form the foundation of route optimization logic.
2. Géron, A. (2019). Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow (2nd ed.).
O’Reilly Media.
A practical guide to machine learning using Python, focusing on regression techniques used for travel time
prediction in this project.
3. Van Rossum, G., & Drake, F. L. (2009). Python 3 Reference Manual. CreateSpace.
The of cial Python reference manual, essential for understanding Python’s syntax, libraries, and
programming features used throughout this project.
4. McKinney, W. (2017). Python for Data Analysis. O’Reilly Media.
Explains the use of Pandas and NumPy for data manipulation, which are used to manage and process
datasets for model training in this project.
5. Lundh, F. (2005). Python Standard Library. O’Reilly Media.
Discusses Python’s built-in libraries, including Tkinter, which was used for designing the graphical user
interface (GUI) of this project.
6. Norton, P. (2020). Python Tkinter Masterclass: A Complete Guide to Mastering Tkinter for GUI
Programming. Independently Published.
Provides guidance on developing interactive Python GUI applications using Tkinter, applied directly in this
project for interface creation.
7. Blum, R., & Bresnahan, C. (2015). Linux Essentials (2nd ed.). Sybex.
Explains basic Linux operations and commands, helpful for running and testing the project on Linux or
macOS platforms.
fi
fi
8. NetworkX Documentation. (2024). Python Network Analysis Library. Retrieved from https://
[Link]
Offers detailed reference on building and visualizing graphs in Python, used for city network visualization
in the project.
9. Matplotlib Documentation. (2024). Python Data Visualization Library. Retrieved from https://
[Link]
Source for creating visual route maps and customizing graph outputs in the visualization module of this
project.