Esempio n. 1
0
    def ga(self):
        network = self.__repo.read_file()
        self.__probParam['noNodes'] = network['noNodes']
        self.__probParam['mat'] = network['mat']
        ga = GA(self.__param, self.__probParam)
        ga.initialisation()
        ga.evaluation()
        g = 0
        fitnessuri = []
        while g < 500:
            # ga.oneGenerationElitism()
            ga.oneGenerationElitism2()
            g += 1
            best_chromo = ga.bestChromosome()
            print('Best solution in generation ' + str(g) + ' is: x = ' +
                  str(best_chromo.repres) + '\nhas fit: ' +
                  str(best_chromo.fitness) + '\n')
            fitnessuri.append(best_chromo.fitness)

        return fitnessuri