-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (35 loc) · 1017 Bytes
/
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
#!/usr/bin/python
# coding=UTF-8
import matplotlib.pyplot as plt, array
from operator import itemgetter
import City as c
import GeneticCode as g
#transforma as rotas em cidades pra ficar legível
nameList = {
"0": "BsB",
"1": "PoA",
"2": "BH",
"3": "Carac.",
"4": "Sant.",
"5": "Bog.",
"6": "Lima",
"7": "RJ",
"8": "BA",
"9": "SP",
}
#determina se uma rota é válida ou não
def is_valid(pops):
valid = True
for i in range(0, len(pops)):
if(len(pops[i]) >= 11):
valid = pops[i][0].id == 0 and pops[i][10].id == 0
else:
valid = False
return valid
#recebendo a melhor rota disponível
bestRoute = g.generateBestRoute(population=c.cities, popSize=100, eliteSize=10, mutationRate=0.01, generations=100)
for i in range(0, len(bestRoute)):
if(i+1 < len(bestRoute)):
print(nameList[ str(bestRoute[i].id) ], end = ' -> ')
else:
print(nameList[ str(bestRoute[i].id) ])