-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInterface.py
More file actions
153 lines (143 loc) · 5.12 KB
/
Interface.py
File metadata and controls
153 lines (143 loc) · 5.12 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import networkx as nx #permite manipulação de grafos
import sys
if sys.version_info[0] <3:
from Tkinter import *
import tkFileDialog as tk
else:
from tkinter import * #Prove interface gráfica para menu
import tkinter.filedialog
import Kruskal as krl
import BFS as bfs
import DFS as dfs
import Dijkstra as dks
import Prim as pr
import WelshPowell as wp
import matplotlib.pyplot as plt
# define options for opening or saving a file
file_opt = options = {}
options['defaultextension'] = '.gexf'
options['initialfile'] = '*.gexf'
def aplica_kruskal():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = krl.Kruskal(G)
pathDoArquivo = pathDoArquivo.replace(".gexf","_MST_Kruskal.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_prim():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = pr.Prim(G, G.nodes()[0])
pathDoArquivo = pathDoArquivo.replace(".gexf","_MST_Prim.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_largura():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = bfs.BFS(G, G.nodes()[0])
pathDoArquivo = pathDoArquivo.replace(".gexf","_BFS.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_profundidade():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = dfs.DFS(G, G.nodes()[0])
pathDoArquivo = pathDoArquivo.replace(".gexf","_DFS.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_dijkstra():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = dks.Dijkstra(G, G.nodes()[0])
pathDoArquivo = pathDoArquivo.replace(".gexf","_Dijkstra.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_coloracao():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
G = wp.WelshPowell(G)
pathDoArquivo = pathDoArquivo.replace(".gexf","_WelshPowell.gexf")
nx.write_gexf(G, pathDoArquivo)
nx.draw(G)
plt.show()
def aplica_todos():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
M = krl.Kruskal(G)
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_MST_Kruskal.gexf")
nx.write_gexf(M, pathDoArquivoNovo)
M = pr.Prim(G, G.nodes()[0])
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_MST_Prim.gexf")
nx.write_gexf(G, pathDoArquivoNovo)
M = bfs.BFS(G, G.nodes()[0])
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_BFS.gexf")
nx.write_gexf(M, pathDoArquivoNovo)
M = dfs.DFS(G, G.nodes()[0])
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_DFS.gexf")
nx.write_gexf(M, pathDoArquivoNovo)
M = dks.Dijkstra(G, G.nodes()[0])
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_Dijkstra.gexf")
nx.write_gexf(M, pathDoArquivoNovo)
M = wp.WelshPowell(G, G.nodes()[0])
pathDoArquivoNovo = pathDoArquivo.replace(".gexf","_WelshPowell.gexf")
nx.write_gexf(M, pathDoArquivoNovo)
def visualizar():
if sys.version_info[0] <3:
pathDoArquivo = tk.Open().show()
else:
pathDoArquivo = filedialog.askopenfilename()
G = nx.read_gexf(pathDoArquivo)
nx.draw(G)
plt.show()
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.kruskal = Button (self, text="MST-Kruskal", command=aplica_kruskal)
self.prim = Button(self, text="MST-Prim", command=aplica_prim)
self.largura = Button(self, text="Busca em Largura", comman=aplica_largura)
self.profundidade = Button(self, text="Busca em Profundidade", command=aplica_profundidade)
self.dijkstra = Button(self, text="Caminhos mínimos - Dijkstra", command=aplica_dijkstra)
self.coloracao = Button(self, text="Coloração de vértices - Welsh & Powell", command=aplica_coloracao)
self.todos = Button(self, text="Exportar todas as transformações", command=aplica_todos)
self.visualizar = Button(self, text="Visualizar", command=visualizar)
self.visualizar.pack()
self.todos.pack()
self.coloracao.pack()
self.dijkstra.pack()
self.profundidade.pack()
self.largura.pack()
self.prim.pack()
self.kruskal.pack ()
self.pack()
app = Application()
app.master.title("Algoritmos em Grafos")
app.master.geometry("280x210+190+80")
mainloop()