-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_of_graph.py
More file actions
352 lines (338 loc) · 11 KB
/
types_of_graph.py
File metadata and controls
352 lines (338 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import cv2
import graph_dsa
import tree
class style():
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
UNDERLINE = '\033[4m'
RESET = '\033[0m'
def undirected_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Undirected Graphs: A graph in which edges have no direction, i.e., the edges do not have arrows indicating the
direction of traversal. Example: A social network graph where friendships are not directional.
""")
input("Enter a key to close: ")
undirected_graph()
elif selector == '2':
img = cv2.imread('graphdirect.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
undirected_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
undirected_graph()
def directed_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Directed Graphs: A graph in which edges have a direction, i.e., the edges have arrows indicating the direction of
traversal. Example: A web page graph where links between pages are directional.
""")
input("Enter a key to close: ")
directed_graph()
elif selector == '2':
img = cv2.imread('graphdirect.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
directed_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
directed_graph()
def wieghted_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Weighted Graphs: A graph in which edges have weights or costs associated with them. Example: A road network graph
where the weights can represent the distance between two cities.
""")
input("Enter a key to close: ")
wieghted_graph()
elif selector == '2':
img = cv2.imread('wgraph.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
wieghted_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
wieghted_graph()
def unwieghted_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Unweighted Graphs: A graph in which edges have no weights or costs associated with them. Example: A social network
graph where the edges represent friendships.
""")
input("Enter a key to close: ")
unwieghted_graph()
elif selector == '2':
img = cv2.imread('unwieghtedgraph.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
unwieghted_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
unwieghted_graph()
def complete_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Complete Graphs: A graph in which each vertex is connected to every other vertex. Example: A tournament graph
where every player plays against every other player.
""")
input("Enter a key to close: ")
complete_graph()
elif selector == '2':
img = cv2.imread('cgraph.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
complete_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
complete_graph()
def bipartite_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Bipartite Graphs: A graph in which the vertices can be divided into two disjoint sets such that every edge connects
a vertex in one set to a vertex in the other set. Example: A job applicant graph where the vertices can be divided
into job applicants and job openings.
""")
input("Enter a key to close: ")
bipartite_graph()
elif selector == '2':
img = cv2.imread('bipartite.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
bipartite_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
bipartite_graph()
def tree_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Trees: A connected graph with no cycles. Example: A family tree where each person is connected to their parents.
""")
input("Enter a key to close: ")
tree_graph()
elif selector == '2':
img = cv2.imread('treegraph.jpg', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
tree_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
tree_graph()
def cycle_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Cycles: A graph with at least one cycle. Example: A bike-sharing graph where the cycles represent the routes
that the bikes take.
""")
input("Enter a key to close: ")
cycle_graph()
elif selector == '2':
img = cv2.imread('cycle.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
cycle_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
cycle_graph()
def sparse_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Sparse Graphs: A graph with relatively few edges compared to the number of vertices. Example: A chemical reaction
graph where each vertex represents a chemical compound and each edge represents a reaction between two compounds.
""")
input("Enter a key to close: ")
sparse_graph()
elif selector == '2':
img = cv2.imread('sparse.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
sparse_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
sparse_graph()
def dense_graph():
print(style.YELLOW + """
[+] Select an option:
1: Definition
2: Image
3: back
""")
selector = input("Enter your choice: ")
if selector == "1":
print("""
Dense Graphs: A graph with many edges compared to the number of vertices. Example: A social network graph where
each vertex represents a person and each edge represents a friendship.
""")
input("Enter a key to close: ")
dense_graph()
elif selector == '2':
img = cv2.imread('sparse.png', cv2.IMREAD_GRAYSCALE)
dim = (450,350)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
cv2.imshow('image', resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
dense_graph()
elif selector == '3':
types_of_graph()
else:
print(style.RED + "Invalid input!!!")
dense_graph()
def types_of_graph():
print(style.GREEN + """
[+] Types of graph is as bellow:
0: general tree
1: Undirected graph
2: Directed Graph
3: Wieghted graph
4: Unwieghted graph
5: complete graph
6: Bipartite graph
7: Trees
8: Cycles
9: Sparse Graph
10: Dense Graph
11: Back
""")
graph_types_selection = input('Enter your selection: ')
if graph_types_selection == '0':
general_tree()
elif graph_types_selection == '1':
undirected_graph()
elif graph_types_selection == '2':
directed_graph()
elif graph_types_selection == '3':
wieghted_graph()
elif graph_types_selection == '4':
unwieghted_graph()
elif graph_types_selection == '5':
complete_graph()
elif graph_types_selection == '6':
bipartite_graph()
elif graph_types_selection == '7':
tree_graph()
elif graph_types_selection == '8':
cycle_graph()
elif graph_types_selection == '9':
sparse_graph()
elif graph_types_selection == '10':
dense_graph()
elif graph_types_selection == '11':
graph_dsa.test()
else:
print(style.RED + "+++INVALID INPUT+++")
types_of_graph()