0% found this document useful (0 votes)
26 views

Cs Proj Pdf_merged

Uploaded by

rahulilayaraja1
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
0% found this document useful (0 votes)
26 views

Cs Proj Pdf_merged

Uploaded by

rahulilayaraja1
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/ 35

PON VIDYASHRAM

GROUP OF CBSE SCHOOLS

Maxworth Nagar, Kolapakkam


Chennai

Project Report
2024 - 2025

Name:
Standard:
Subject:

Reg. No.:
Title of the Project:
BONAFIDE CERTIFICATE

Certified to be the bonafide project work done by


_________________ of Std XII in the _________
Laboratory of Pon Vidyashram Chennai – 600128,
during the academic year 2024 – 2025.

Date Teacher-in-charge

Submitted for the AISSCE Practical Examination held on


_____________ at Pon Vidyashram Chennai – 600128.

Internal External Principal


Examiner Examiner
ACKNOWLEDGEMENT

First and foremost. I would like to express my sincere gratitude


to the Almighty who has enabled me to complete this project
successfully.
Next, I would like to extend my gratitude to my School and my
Principal, Mrs. B. Kalpana, for fostering an environment of
learning and creativity within our school.
I’m highly indebted to my teacher ____________________ for
providing me with invaluable insights, mentoring and supporting
me in completing this project,
____________________________________________________
My sincere appreciation also goes to the laboratory assistant
_________________. I would also like to thank my parents for
their Constant Encouragement, Patience and Understanding,
which have been the pillars of my success. I am grateful to my
friends who contributed ideas and perspectives that enriched the
project.
Once again, I thank you all for shaping this project and
enhancing my learning experience.
TABLE OF CONTENTS:

CH. CHAPTER PAGE


NO. NO.

1 INTRODUCTION 2

2 OBJECTIVE 3

3 ALGORITHM 4

4 MINIMUM HARDWARE SPECIFICATIONS 4

5 MINIMUM SOFTWARE SPECIFICATIONS 5

6 SYSTEM DESIGN 6

7 MODULES USED 13

8 SOURCE CODE 14

9 OUTPUT 24

10 FUTURE ENHANCEMENTS 30

11 CONCLUSION 31

12 BIBLIOGRAPHY 32

1
1. INTRODUCTION:
A minimum spanning tree is the subset of a graph where all the points in the given graph

is connected with minimum cost (path traversed). Finding the minimum distance

between multiple points has been a powerful tool in solving problems for the modern

era engineers since the 1930 when it was first published by Czech scientist Otakar

Borůvka for efficient power transmission across the city of Moarvia. More commonly

used alogirthms to solve such problems are Prim’s algorithm and Kruskal’s algorithm.

This project aims to solve problems with sparse graphs (3 to ~10⁶ points) hence we

chose Kruskal’s algorithm over Prim’s algorithm as,

 More efficient for smaller graphs

 Simpler to implement

 Independent of selecting starting point

 Minimal computer hardware use

The minimum spanning tree is built on python using kruskal’s algorithm helps in

various fields for example:

 Building connected networks (Electrical gird, computer network)

 Handwriting recognition

 Image registration and segmentation

 Cluster analysis

2
2. OBJECTIVE:
The ultimate motive behind this project is to allow people with any amount of

knowledge and experience with MST’s to access MST for solving real life problems in

a simple, understandable and effective manner.

The simple code used helps any one with data to find relationships in it, optimise their

solution for a specific problem, foster more interested into the beautiful and highly

useful world of graphs.

It also aims towards solving complex engineering problems faced by people from all

parts of science such as:

 Help biologists conducting ecotoxicology to better understand movement of

pollutant particles through human body and make better medicine.

 Optimise networks for maximum efficiency and minimum cost.

 Conduct genetic research to better understand human biology.

3
3. ALGORITHM:
Kruskal's algorithm works to find the Minimum Spanning Tree (MST) of a graph by

following these steps:

1) Sort all edges: Arrange all the edges in non-decreasing order based on their

weights.

2) Initialize a disjoint-set: Create a disjoint-set (also called a union-find) data

structure to manage the connected components of the graph.

3) Select edges: Start from the smallest edge and check if they have dissimilar

parents,

4) Add edge if no cycle detected: If the edge does not form a cycle (i.e., they have

different parent) add it to the MST and change rank.

5) Repeat: Continue this process until the MST contains exactly (number of

points -1) number of vertices.

6) Terminate: The algorithm terminates when all vertices are connected and there

is only one parent in MST.

The following process ensures that the MST has the least possible edge weight sum

while connecting all vertices.

4
4. MINIMUM HARDWARE SPECIFICATIONS:
Processor : Intel i3 – 6100 (2.7 GHz) / AMD Ryzen 3 1200 (3.1 GHz)

Graphics card : Intel HD Graphics 520 / AMD Radeon Vega 3

RAM : 10 GB (SSD/HDD)

Disk capacity : 500 MB

5. MINIMUM SOFTWARE SPECIFICATIONS:


OS : Windows 7 (64 bit) or later / macOS 10.12 or later

Python : Python 3.6 or later

5
6. SYSTEM DESIGN:

In this phase, a logical system is built which fulfils the given requirements. Design phase

of software development deals with transforming the client’s requirements into a

logically working system. Normally, design is performed in the following two steps:

1. Primary Design phase:

Here the system is designed at block level. The blocks are created on the basis of

analysis done in the problem identification phase. Different blocks are created for

different functions emphasis is put on minimising the information flow between blocks.

Thus, all activities which require more interaction are kept in one block.

2. Secondary Design phase:

In the secondary phase the detailed design of every block is performed.

The general tasks involved in the design process are the following:

 Design various blocks for overall system processes.

 Design various database structures

 Specify details of programs to achieve desired functionality.

 Design the form of inputs, and outputs of the system.

 System reviews.

6
Getting choice from user

For recieving coordinates from file

7
For recieving number of points for random coordiantes

8
Recieving necessary run conditions from
user
9
A manual simulation of flow of air
through lungs.

10
An automatic random points run
11
Output in given file
12
7. MODULES USED:

 tkinter : tkinter is used to create the GUI.

 random : random is used to simulate random coordinates for the MST.

 math : math module is used for distance calculation.

 ast : ast is used to read data from file in original form.

 copy : copy is used to form deep copy of list to count number of parents.

 time : time used to simulate the timed run.

13
8. SOURCE CODE:
import copy
import time
import tkinter as tk
import random as rd
import math
import ast

GUI = tk.Tk()
GUI.attributes('-fullscreen', True)

f_name = 0
k = 0
next = 0
ch = 0
np = 0
o = 0
file = 0
k = True
canvas = None
oval_cords = []
dist_list = []
min_dist_order_list = []
visited = []
final_tree = []

no_of_points_box = 0
no_of_points_box_entry = 0
time_b_val = 0
mode_b_val = 0
branch_b_val = 0

no_pt = 0

timee = 0
mode = 0
branch = 0
total_cost = 0
f_name = 0
text = 0

def on_right_click(event):
GUI.quit()

GUI.bind("<Button-3>", on_right_click)

14
def create_canvas():
global canvas
canvas = tk.Canvas(GUI, bg='#E0FFFF', height=GUI.winfo_height()-50,
width=GUI.winfo_width())
canvas.grid(row=0, column=0, sticky='nsew')
return canvas

def random_cords():
global canvas, np
canvas = create_canvas()
canvas.update()
canvas_width = canvas.winfo_width()-10
canvas_height = canvas.winfo_height()-100
for i in range(np):
x = rd.randint(0, canvas_width-15)
y = rd.randint(0, canvas_height-100)
canvas.create_oval(x - 5, y - 5, x + 5, y + 5, fill='blue')
global oval_cords
oval_cords.append([str(i),[x,y]])

canvas.create_text(x + 10, y - 10, text=str(i), fill="red", font=("Arial",


10))

dist_lst_calc()

def get_np():
global np, no_of_points_box, no_of_points_box_entry

random_btn.destroy()
input_file_btn.destroy()
choice_label.destroy()

no_of_points_box = tk.Button(text='Enter the number of points in your minimum


spanning tree here and press button to enter value: ',
command=np_calc , relief=tk.RAISED, bg = 'black', fg =
'white', font = ('Courier New',13))

no_of_points_box.place(anchor = 'se', relx = 0.8, rely = 0.5)

no_of_points_box_entry = tk.Entry(relief=tk.GROOVE, bg='grey')


no_of_points_box_entry.place(anchor='se',relx = 0.5, rely = 0.56, width = 100,
height = 25)

15
def np_calc():
global np, no_of_points_box, no_of_points_box_entry

np = no_of_points_box_entry.get()
np = int(np)
no_of_points_box.destroy()
no_of_points_box_entry.destroy()

method()

def dist_lst_calc():
global oval_cords, dist_list, min_dist_order_list, np
global timee, mode, branch

for j in range(np):
x1 = oval_cords[j][1][0]
y1 = oval_cords[j][1][1]

for k in range(j+1, np):


x2 = oval_cords[k][1][0]
y2 = oval_cords[k][1][1]
dist = round(math.sqrt((x2 - x1)**2 + (y2 - y1)**2), 5)
dist_list.append([dist, [j, k]])
min_dist_order_list = sorted(dist_list, key=lambda x: x[0])

graph_lines_calc()

def root(lst, index):


if lst[index][1] == -1:
return index
else:
lst[index][1] = root(lst, lst[index][1])
return lst[index][1]

def method():
global time_b_val, mode_b_val, branch_b_val

w_msg.destroy()

if o == 1:
f_name.destroy()
k.destroy()

16
instructions = tk.Label(text =
''' **INSTRUCTIONS**:
------------

1. To run code in manual mode give mode as 1 and to run code in automatic mode give
mode as 0

2. Input the time between every code run in the *TIME* box. (For instant output and
manual mode give t as 0)

3. Enter the numbers of braches to connect at a time in the *BRANCH* box. (Branch
>0)

Press *EXECUTE* button after parameter are given''',


font = ('Courier New',13), fg = 'white', bg = 'black', anchor = 'w', justify=
'left')
instructions.place(relx = 0, rely = 0)

time_b = tk.Label(text= 'Time', font = ('Courier New',11) , fg = 'white', bg =


'black')
time_b.place(relx = 0, rely = 0.28)

time_b_val = tk.Entry(relief=tk.GROOVE, bg='grey')


time_b_val.place(relx = 0.05, rely = 0.28)

mode_b = tk.Label(text='Mode', font = ('Courier New',11) , fg = 'white', bg =


black')
mode_b.place(relx = 0, rely = 0.33)

mode_b_val = tk.Entry(relief=tk.GROOVE, bg='grey')


mode_b_val.place(relx = 0.05, rely = 0.33)

brach_b = tk.Label(text = 'Branch',font = ('Courier New',11) , fg = 'white',


bg = 'black')
brach_b.place(relx = 0, rely = 0.38)

branch_b_val = tk.Entry(relief=tk.GROOVE, bg='grey')


branch_b_val.place(relx = 0.05, rely = 0.38)

enter_b = tk.Button(text = 'Execute', command = lambda: method_sec(), font =


('Courier New',11) , fg = 'white', bg = 'red', activeforeground =
'blue')
enter_b.place(relx = 0.21, rely = 0.33)

17
def method_sec():
global timee,mode,branch, canvas
global canvas, np, min_dist_order_list

timee = int(time_b_val.get())
mode = int(mode_b_val.get())
branch = int(branch_b_val.get())

if o == 0:
random_cords()
elif o == 1:
cords()

def sui():
global k, no_pt, np, next, ch, n
global visited, min_dist_order_list, oval_cords, canvas, final_tree , total_cost

n = 0

pseudo_lst = copy.deepcopy(visited)
while pseudo_lst != []:
c = pseudo_lst.pop()
if c[1] == -1:
n+=1

if mode == 0:

if len(min_dist_order_list) > 0:
pts = min_dist_order_list.pop(0)

from_pt = pts[1][0]
to_pt = pts[1][1]

parent_1 = root(visited, from_pt)


parent_2 = root(visited, to_pt)

if parent_1 != parent_2:

if timee != 0:
GUI.update()
time.sleep(timee)

visited[parent_2][1] = parent_1
final_tree.append(pts)
total_cost += pts[0]

18
for p in oval_cords:
if int(p[0]) == from_pt:
x1 = p[1][0]
y1 = p[1][1]
elif int(p[0]) == to_pt:
x2 = p[1][0]
y2 = p[1][1]
canvas.create_line(x1,y1,x2,y2,fill = 'blue')
no_pt += 1

else:
sui()

elif n == 1:
msg = tk.Label(text = 'MST constructed :)', font = ('Courier New',11),
fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)

ch = tk.Button(text = 'Press button to store data in file', font =


('Courier New',11), fg = 'black', bg = 'light blue', command =
data_to_file, relief = 'raised')
ch.place(relx = 0.05, rely = 0.96)

else:
msg = tk.Label(text = 'MST constructed :)', font = ('Courier New',11),
fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)

ch = tk.Button(text = 'Press button to store data in file', font =


('Courier New',11), fg = 'black',bg = 'light blue', command =
data_to_file, relief = 'raised')
ch.place(relx = 0.05, rely = 0.96)

elif mode == 1:

for t in range(branch):
if len(min_dist_order_list) > 0:
pts = min_dist_order_list.pop(0)

from_pt = pts[1][0]
to_pt = pts[1][1]

parent_1 = root(visited, from_pt)


parent_2 = root(visited, to_pt)

19
if parent_1 != parent_2:

if timee != 0:
GUI.update()
time.sleep(timee)

visited[parent_2][1] = parent_1
final_tree.append(pts)
total_cost += pts[0]

for p in oval_cords:
if int(p[0]) == from_pt:
x1 = p[1][0]
y1 = p[1][1]
elif int(p[0]) == to_pt:
x2 = p[1][0]
y2 = p[1][1]
canvas.create_line(x1,y1,x2,y2,fill = 'blue')
no_pt += 1

else:
sui()

else:
next.destroy()
msg = tk.Label(text = 'MST constructed :)', font = ('Courier
New',11), fg = 'black', bg = 'light blue')
msg.place(relx = 0.46, rely = 0.96)

ch = tk.Button(text = 'Press button to store data in file', font =


('Courier New',11), fg = 'black',
bg = 'light blue', command = data_to_file )
ch.place(relx = 0.05, rely = 0.96)

break

def data_to_file():
global file, text
ch.destroy()

text = tk.Button(text = 'Enter file path and press button: ', font = ('Courier
New',11), fg = 'white', bg = 'black',command = enter_data)
text.place(relx = 0, rely = 0.96)

file = tk.Entry(relief=tk.GROOVE, bg='grey')


file.place(relx = 0.25, rely = 0.96)

20
def enter_data():
global file, total_cost
f = file.get()

with open(f,'w+') as fi:

while len(final_tree) > 0:


fo = final_tree.pop(0)
fi.write(str(fo) + '\n')

fi.write('\n')
fi.write('Total cost' + str(total_cost))

file.destroy()
text.destroy()

def graph_lines_calc():
global k, n, no_pt
global min_dist_order_list, oval_cords, canvas, visited, next
global timee, mode, branch

if len(visited) <np:
for i in range(np):
visited.append([i,-1])

if mode == 0:

while no_pt < (np - 1) and len(min_dist_order_list) > 0:


for t in range(branch):
sui()

elif mode == 1:

next = tk.Button(text = 'NEXT', command = sui, fg = 'black', bg = 'red')


next.place(relx=0.5, rely=0.98, anchor='se')

def get_list():
global oval_cords, f_name, o

file = f_name.get()
f = open(file,'r')

oval_cords = f.read()
oval_cords = ast.literal_eval(oval_cords)
o = 1
method()

21
def get_file():
global f_name, k, f_name

random_btn.destroy()
input_file_btn.destroy()
choice_label.destroy()

k = tk.Button(text= 'Enter the file name in the input box', command =


get_list, font = ('Courier New',11), fg = 'white', bg = 'black')
k.place(anchor = 'se' ,relx = 0.5, rely = 0.5)

f_name = tk.Entry(relief=tk.GROOVE, bg='grey')


f_name.place(relx = 0.505, rely = 0.47)

def cords():
global oval_cords,canvas,np

canvas = create_canvas()
canvas.update()
canvas_width = canvas.winfo_width()
canvas_height = canvas.winfo_height()-100

pseudo_list = copy.deepcopy(oval_cords)
while len(pseudo_list) > 0:

cord = pseudo_list.pop(0)
x = cord[1][0]
y = cord[1][1]
i = cord[0]
canvas.create_oval(x - 5, y - 5, x + 5, y + 5, fill='blue')
canvas.create_text(x + 10, y - 10, text=str(np), fill="red", font=("Arial",
10))
np+=1

dist_lst_calc()

w_msg = tk.Label(text = 'Welcome to Minimum Spanning Tree Program :) ', bg = 'light


blue', fg ='black', font = ('Courier',19), border = 10 , bd =5 )
w_msg.place(relx = 0.28, rely = 0.0)

choice_label = tk.Label(text = 'Choose the way you want to use the program with:',
bg = 'black', fg = 'white', font = ('Courier New',15), relief =
'raised')
choice_label.place(relx = 0.3, rely = 0.4)

random_btn = tk.Button(text='1. Random coordinates', command= get_np,


background='black', fg = 'white', font = ('Courier New',11), relief = 'raised')
random_btn.place(anchor='se', relx=0.433, rely=0.5)

22
input_file_btn = tk.Button(text='2. Input coordinates via file', command= get_file ,
background= 'black', fg = 'white', font = ('Courier New',11),
relief = 'raised')
input_file_btn.place(anchor='se', relx=0.68, rely=0.5)

exit_b = tk.Button(text = 'EXIT', font = ('Courier New',9), command = exit, fg =


'white', bg = 'black')
exit_b.place(relx = 0.96, rely = 0.96)

GUI.mainloop()

23
9. OUTPUT:
 Simulation of air through human lungs (Coordinates from file):

24
25
26
27
 Random Coordinates simulation:

28
29
10. FUTURE ENHANCMENTS:

 Implement color-coded edges to represent weight differences in the Minimum

Spanning Tree (MST), helping users better understand the cost of connection.

 Make some modifications in the sui() function to join points under specific

distance and use for clustering data.

 Add support for weighted graphs where users can specify edge weights directly.

 Implement graph drawing tools, enabling users to draw and interact with their

own graphs.

 Providing zooming/panning options for improved visualization.

 Display real-time performance metrics such as execution time, memory usage,

and the number of iterations performed during the algorithm.

 Provide options to export the MST as an image, CSV file, or in standard graph

formats like GraphML or JSON for external analysis.

30
11. CONCLUSION:
This Minimum Spanning Tree program is a solid starting point for anyone looking to

understand or work with MSTs. Whether you’re a student learning the basics or a

professional solving practical problems, the program delivers on its promise of

simplicity and functionality. It visualizes the problem in an easy-to-follow way, making

it much less intimidating for newcomers to grasp the concept.

This isn’t just a tool for fun; it has real-world applications. From designing networks to

planning routes, finding an MST is something engineers and researchers deal with all

the time. The ability to save results is another practical touch, ensuring the data can be

used later in more detailed analysis or presentations.

That said, there’s still plenty of room for improvement. Adding more features like

support for different MST algorithms, better visualization, or the ability to work with

larger datasets would take this program to higher levels.

In short, this program has done a great job at being both educational and functional. It

simplifies a tricky mathematical concept and makes it easy to see it in action. With a

few enhancements in the future, it has the potential to become more visually interesting,

practical and useful for the user. It’s a reminder of how coding can take abstract ideas

and make them something tangible and practical.

31
BIBILIOGRAPHY:

References:
 https://www.youtube.com/playlist?list=PLEJXowNB4kPzByLnnFYNSCoqtFz0

VKLk5

 https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-

greedy-algo-2

 https://stackoverflow.com/questions/58199612/how-to-display-a-complete-text-

in-tkinter-gui-in-python

 www.chatgpt.com

 https://personal.utdallas.edu/~besp/teaching/mst-applications.pdf

 https://docs.python.org/3/library/tkinter.html

Books:

 Computer science with Python Class XII, Sumita Arora, Dhanapat Rai and Co,
15th edition.

32

You might also like