forked from arthursrr/GraphMinimalColoringBRKGA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (36 loc) · 1.42 KB
/
main.py
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
import BRKGA
import graph as gr
import individuo as ind
import populacao as pp
import time
import glob
if __name__ == "__main__":
listFile = ["../kgb/*.clq", "../kgb/*.txt"]
for ext in listFile:
for file in glob.glob(ext):
fileg = open(file, 'r')
first = 0
tempoLimite = 0.5 #tempo em minutos
tempo = time.time()
for line in fileg:
if first == 0:
line1 = line.split(" ")
tam = int(line1[2])
first = 1
grafo = gr.Graph(tam)
else:
lineE = line.split(" ")
v1 = int(lineE[1]) - 1
v2 = int(lineE[2]) - 1
grafo.addEdge(v1, v2)
Populacao = pp.Population(10, True, grafo.numVert, grafo.numColor, grafo.edges)
TAXA = BRKGA.BRKGA()
print()
geracoes = 0
while (int(time.time()- tempo)/60) < tempoLimite:
Populacao = TAXA.Evoluir(Populacao, Populacao.tamPopulacao, grafo.numVert, grafo.numColor, grafo.edges)
geracoes += 1
elite = Populacao.getEliteFromFitness(TAXA.taxaSobrevivencia)
coresUsadas = elite[0].colors
print("Total de cores usadas => ", coresUsadas)
print("Total de gerações -> ", geracoes)