-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·90 lines (84 loc) · 2.08 KB
/
main.py
File metadata and controls
executable file
·90 lines (84 loc) · 2.08 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
# -*- coding: utf-8 -*-
import Graph
# Main function calling the GUI
def main():
gui()
# Lets the user control the program via the text bases GUI
def gui():
g = Graph.Graph()
#For test purpose
a = g.add_vertex(4)
b = g.add_vertex(5)
c = g.add_vertex(3)
d = g.add_vertex(2)
e = g.add_vertex(7)
g.addEdge(a,b,2)
g.addEdge(a,c,2)
g.addEdge(b,d,1)
g.addEdge(c,d,1)
g.addEdge(c,e,1)
g.addEdge(d,e,3)
# a = g.add_vertex(7)
# b = g.add_vertex(5)
# c = g.add_vertex(3)
# d = g.add_vertex(11)
# e = g.add_vertex(8)
# f = g.add_vertex(2)
# h = g.add_vertex(9)
# i = g.add_vertex(10)
# g.addEdge(a,d,1)
# g.addEdge(a,e,1)
# g.addEdge(b,d,1)
# g.addEdge(c,e,1)
# g.addEdge(c,i,1)
# g.addEdge(d,f,1)
# g.addEdge(d,h,1)
# g.addEdge(d,i,1)
# g.addEdge(e,h,1)
# g.addEdge(h,i,5)
print_menu()
while True:
input = raw_input("Input selection \n")
if(input == '1'):
print "Noob"
elif(input == '2'):
weight = raw_input("Choose a weight to the vertice \n")
v = g.add_vertex(weight)
print "Vertex identifier: " + v
elif(input == '3'):
a = raw_input("Choose first vertice \n")
b = raw_input("Choose second vertice \n")
w = raw_input("Choose a weight for the edge \n")
g.addEdge(a,b,w)
elif(input == '4'):
print g.getVertices()
elif(input == '5'):
n = raw_input("Choose vertice \n")
print g.getVertex(n)
elif(input == '6'):
print_menu()
elif(input == '7'):
break;
elif(input == '8'):
g.topologicalOrdering()
elif(input == '9'):
a = raw_input("Choose start vertice\n")
b = raw_input("Choose end vertice\n")
g.weightOfLongestPath(a,b)
# Prints the menu
def print_menu():
print "Options"
print "1. Help"
print "2. Add node"
print "3. Add edge"
print "4. Display vertices"
print "5. Display connections"
print "6. Display menu"
print "7. Quit program"
print "8. Topological Ordering"
print "9. Longest Path"
# Create an empty graph
def create_graph():
return Graph.Graph()
# Run main
main()