-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
131 lines (116 loc) · 3.94 KB
/
app.py
File metadata and controls
131 lines (116 loc) · 3.94 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
# from graph import Graph
from undigraph import Undigraph
from digraph import Digraph
import view_aux as v_x
# import sys
import os
import argparse
def main():
"""Gets arguments from user, builds up the graph and calls menu"""
text = "INE5413 Assignment: Graph Theory\n\
Example: \n\
app.py 1 datasets/contem_ciclo.txt\n\
or\n\
app.py 1 datasets/dirigido1.txt --digraph --arcs\n\
or\n\
app.py 1 datasets/pequeno.txt --bipartite"
# initiate the parser
parser = argparse.ArgumentParser(description=text, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("id", help="set graph identification")
parser.add_argument("dataset", help="set input data")
parser.add_argument("--digraph",
help="set graph as digraph (default is undigraph)",
action="store_true")
parser.add_argument("--arcs",
help="set file separator as *arcs (default is *edges)",
action="store_true")
parser.add_argument("--bipartite",
help="set graph as a bipartite graph (it's a undigraph)",
action="store_true")
# read arguments from the command line
args = parser.parse_args()
ID = args.id
DATASET = args.dataset
if args.digraph:
graph = Digraph(ID)
else:
graph = Undigraph(ID)
print(DATASET)
graph.read_file(DATASET, args.arcs, args.digraph, args.bipartite)
menu(graph, args.digraph)
def menu(graph, isDigraph):
while True:
os.system('clear')
print('Graph:', graph.identification)
print('Please select: ')
print('1: Print Vertices')
print('2: Print Edges')
print('3: Verify Edge (weight included)')
print('4: Verify Vertice (neighbours and label included)')
print('5: Draw Graph')
if (isDigraph):
menu_digraph(graph)
else:
menu_undigraph(graph)
sel = int(input())
if sel == 0:
print('Goodbye :)')
break
if sel == 1:
print('Vertices names: ', graph.vertices_names)
print('Size: ', len(graph.vertices_names))
input('Press enter to continue...')
if sel == 2:
print('Edges: ', graph.edges)
print('Size: ', len(graph.edges))
input('Press enter to continue...')
if sel == 3:
v_x.sel_verify_edge(graph)
if sel == 4:
v_x.sel_verify_vertice(graph)
if sel == 5:
if graph.num_edges() > 50:
print('Graph too long to draw!')
input('Press enter to continue...')
else:
print('Insert filename: ')
filename = input()
graph.draw(filename)
if (sel > 5 and sel <= 11):
menu_aux(graph, isDigraph, sel)
def menu_aux(graph, isDigraph, sel):
if isDigraph:
if sel == 6:
v_x.sel_scc(graph)
if sel == 7:
v_x.sel_tps(graph)
if sel == 8:
v_x.sel_edmonds_karp(graph)
else:
if sel == 6:
v_x.sel_bfs(graph)
if sel == 7:
v_x.sel_hierholzer(graph)
if sel == 8:
v_x.sel_bfa(graph)
if sel == 9:
v_x.sel_floyd_warshall(graph)
if sel == 10:
v_x.sel_prim(graph)
if sel == 11:
v_x.sel_hk(graph)
def menu_digraph(graph):
print('6: Strongly Connected Components')
print('7: Topological Sorting')
print('8: Edmonds-Karp Algorithm')
print('0: Exit')
def menu_undigraph(graph):
print('6: Breadth First Search')
print('7: Eulerian Cicle')
print('8: Bellman-Ford Algorithm')
print('9: Floyd-Warshall Algorithm')
print('10: Prim Algorithm')
print('11: Hopcraft-Karp Algorithm')
print('0: Exit')
if __name__ == "__main__":
main()