def test(self):
        estados = carrega_dados("adjacent_states.csv")
        regras = contruir_regras(estados)
        valorOtimo = len(regras)
        indiceEstadoLookup = {
            key: index
            for index, key in enumerate(sorted(estados))
        }

        cores = ["laranja", "Amarelo", "Verde", "Azul"]
        corLookup = {cor[0]: cor for cor in cores}
        geneset = list(corLookup.keys())

        iniciaTempo = datetime.datetime.now()

        def fnTela(candidato):
            tela(candidato, iniciaTempo)

        def fnAptidao(genes):
            return avalia_aptidao(genes, regras, indiceEstadoLookup)

        melhor = genetico.oMelhor(fnAptidao, len(estados), valorOtimo, geneset,
                                  fnTela)
        self.assertTrue(not valorOtimo > melhor.Aptidao)
        chaves = sorted(estados.keys())
        for indice in range(len(estados)):
            print(chaves[indice] + "é" + corLookup[melhor.Genes[indice]])
Beispiel #2
0
    def ordena_numeros(self, totalNumeros):
        geneSet = [i for i in range(100)]
        iniciaTempo = datetime.datetime.now()

        def fnTela(candidato):
            tela(candidato, iniciaTempo)

        def fnAptidao(genes):
            return avalia_apitidao(genes)

        aptidaoOtima = Aptidao(totalNumeros, 0)
        melhor = genetico.oMelhor(fnAptidao, totalNumeros, aptidaoOtima,
                                  geneSet, fnTela)
        self.assertTrue(not aptidaoOtima > melhor.Aptidao)
Beispiel #3
0
    def test(self, tamanho=8):
        geneset = [i for i in range(tamanho)]
        iniciaTempo = datetime.datetime.now()

        def fnTela(candidato):
            tela(candidato, iniciaTempo, tamanho)

        def fnAptidao(genes):
            return avalia_aptidao(genes, tamanho)

        aptidaoOtima = Aptidao(0)
        melhor = genetico.oMelhor(fnAptidao, 2 * tamanho,
                                  aptidaoOtima, geneset, fnTela)
        self.assertTrue(not aptidaoOtima > melhor.Aptidao)
Beispiel #4
0
    def test(self, tamanho=100):
        geneset = [0, 1]
        iniciaTempo = datetime.datetime.now()

        def fnTela(candidato):
            tela(candidato, iniciaTempo)

        def fnAptidao(genes):
            return avalia_aptidao(genes)

        aptidaoOtima = tamanho
        melhor = genetico.oMelhor(fnAptidao, tamanho, aptidaoOtima, geneset,
                                  fnTela)
        self.assertEqual(melhor.Aptidao, aptidaoOtima)
    def adivinha_senha(self, alvo):

        iniciaTempo = datetime.datetime.now()

        def fnAptidao(genes):
            return avalia_aptidao(genes, alvo)

        def fnTela(candidato):
            tela(candidato, iniciaTempo)

        aptidaoOtima = len(alvo)
        melhor = genetico.oMelhor(fnAptidao, len(alvo), aptidaoOtima,
                                  self.geneset, fnTela)

        self.assertEqual(melhor.Genes, alvo)